import '../../../utils/json_converter.dart';

class BookPackageItem {
  final int? id;                        // ID
  final String? createUserString;       // 创建用户
  final String? createTime;             // 创建时间
  final String? name;                   // 书名
  final String? isbn;                   // 国际标准书号
  final String? author;                 // 作者
  final String? keyword;                // 关键词
  final String? publisher;              // 出版社
  final String? imageUrl;               // 图片URL
  final double? referencePrice;         // 参考价格
  final int? categoryId;                // 分类ID
  final String? updateTime;             // 更新时间
  final bool? isDeleted;                // 是否删除
  final int? packageId;                 // 套餐ID
  final int? bookId;                    // 书籍ID
  final int? quantity;                  // 数量
  final double? itemPrice;              // 项目价格

  BookPackageItem({
    this.id,
    this.createUserString,
    this.createTime,
    this.name,
    this.isbn,
    this.author,
    this.keyword,
    this.publisher,
    this.imageUrl,
    this.referencePrice,
    this.categoryId,
    this.updateTime,
    this.isDeleted,
    this.packageId,
    this.bookId,
    this.quantity,
    this.itemPrice,
  });

  factory BookPackageItem.fromJson(Map<String, dynamic> json) {
    return BookPackageItem(
      id: JsonConverter.toInt(json['id']),
      createUserString: JsonConverter.toStr(json['createUserString']),
      createTime: JsonConverter.toStr(json['createTime']),
      name: JsonConverter.toStr(json['name']),
      isbn: JsonConverter.toStr(json['isbn']),
      author: JsonConverter.toStr(json['author']),
      keyword: JsonConverter.toStr(json['keyword']),
      publisher: JsonConverter.toStr(json['publisher']),
      imageUrl: JsonConverter.toStr(json['imageUrl']),
      referencePrice: JsonConverter.toDouble(json['referencePrice']),
      categoryId: JsonConverter.toInt(json['categoryId']),
      updateTime: JsonConverter.toStr(json['updateTime']),
      isDeleted: JsonConverter.toBool(json['isDeleted']),
      packageId: JsonConverter.toInt(json['packageId']),
      bookId: JsonConverter.toInt(json['bookId']),
      quantity: JsonConverter.toInt(json['quantity']),
      itemPrice: JsonConverter.toDouble(json['itemPrice']),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'createUserString': createUserString,
      'createTime': createTime,
      'name': name,
      'isbn': isbn,
      'author': author,
      'keyword': keyword,
      'publisher': publisher,
      'imageUrl': imageUrl,
      'referencePrice': referencePrice,
      'categoryId': categoryId,
      'updateTime': updateTime,
      'isDeleted': isDeleted,
      'packageId': packageId,
      'bookId': bookId,
      'quantity': quantity,
      'itemPrice': itemPrice,
    };
  }
}